fix(www): prevent command menu copy shortcut from hijacking clipboard when closed#10423
Open
yogeshwaran-c wants to merge 1 commit intoshadcn-ui:mainfrom
Open
fix(www): prevent command menu copy shortcut from hijacking clipboard when closed#10423yogeshwaran-c wants to merge 1 commit intoshadcn-ui:mainfrom
yogeshwaran-c wants to merge 1 commit intoshadcn-ui:mainfrom
Conversation
… when closed The Ctrl/Cmd+C handler in the docs command menu fires globally and copies the last highlighted item's payload regardless of whether the dialog is open, overriding normal clipboard copies on the rest of the page. When no item was highlighted it would also copy an empty string, effectively clearing the clipboard. Gate the copy branch on the dialog being open and a non-empty payload, using a ref to read the latest open state without resubscribing on every toggle. Fixes shadcn-ui#9242
Contributor
|
@yogeshwaran-c is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
The docs site command menu (
apps/v4/components/command-menu.tsx) installs a globalkeydownlistener that listens for Ctrl/Cmd+C. The handler fires regardless of whether the dialog is open, so after the user opens the search, highlights a component/color/block and then closes the dialog, every subsequent Ctrl/Cmd+C on the rest of the page copies the last highlighted item'scopyPayloadinstead of the user's selected text. If the dialog is opened without anything being highlighted (copyPayloadis an empty string), Ctrl/Cmd+C writes an empty string to the clipboard, effectively clearing it.Closes #9242
What is the new behavior?
The Ctrl/Cmd+C branch now early-returns unless the dialog is currently open and a non-empty
copyPayloadis staged. The open state is read through a ref that is kept in sync via a small effect, so the handler does not need to resubscribe on every open/close toggle.Additional context
e.preventDefault()behavior is unchanged; browser default copy is no longer pre-empted when the menu is closed.apps/v4is in the changesetsignorelist, so no changeset is needed.